<?php

function post_type_active()
{
	$args=array(
			'public'=>true,
			'publicly_queryable'=>true,
			'hierarchical' => false,
			'labels'=>array(
    									'name' => _x('秒杀产品', 'post type general name'),
    									'singular_name' => _x('秒杀产品', 'post type singular name'),
    									'add_new' => _x('添加新秒杀产品', '秒杀产品'),
    									'add_new_item' => __('添加新秒杀产品'),
    									'edit_item' => __('编辑秒杀产品'),
    									'new_item' => __('新的秒杀产品'),
    								//	'view_item' => __('预览店铺'),
    									'search_items' => __('搜索秒杀产品'),
    									'not_found' =>  __('您还没有发布秒杀产品'),
    									'not_found_in_trash' => __('回收站中没有秒杀产品信息'), 
    									'parent_item_colon' => ''
  										),
                             'show_ui' => true,
							 'menu_position'=>5,
							 'supports' => array(
												'title',
												'author', 
											//	'excerpt',
												'thumbnail',
												'editor'
													) ,
							'show_in_nav_menus'	=> true ,
							'taxonomies'		=> array('menutype')	
			);
	register_post_type('active',$args);	
}

add_action('init',post_type_active);



function create_active_taxonomy() 
{
  $labels = array(
	  						  'name' => _x( '活动分类', 'taxonomy general name' ),
    						  'singular_name' => _x( 'videos', 'taxonomy singular name' ),
    						  'search_items' =>  __( '搜索分类' ),
   							  'all_items' => __( '全部分类' ),
    						  'parent_item' => __( '父级分类目录' ),
   					   		  'parent_item_colon' => __( '父级分类目录:' ),
   							  'edit_item' => __( '编辑活动分类' ), 
  							  'update_item' => __( '更新' ),
  							  'add_new_item' => __( '添加新活动分类' ),
  							  'new_item_name' => __( 'New Genre Name' ),
  ); 
  register_taxonomy('active_tax',array('active'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'active_tax' ),
  ));
}
add_action( 'init', 'create_active_taxonomy', 0 );




function admin_init_active(){
	
	add_meta_box("et_active_meta", "秒杀产品", "et_post_active_meta", "active", "normal", "high");
	//add_meta_box("et_active_meta", "活动名称简介", "et_post_active_title_meta", "active", "normal", "high");
}
add_action("admin_init", "admin_init_active");

function et_post_active_meta($callback_args) {
	global $post;
	$thumbs = array();
	$custom    = get_post_custom($post->ID);
	$nums     = isset($custom["pos"][0]) ? $custom["pos"][0] : '';
	$titlename     = isset($custom["titlename"][0]) ? $custom["titlename"][0] : '';
 ?>
     <p style="margin-bottom: 22px;height:50px">
     
     <span style='float:left;display:inline-block;'>
		<label for="et_nums">秒杀数量: </label>
       <input name="et_nums" type="text" id="et_nums"  value="<?php echo $nums;?>" title="请秒杀数量" onKeyUp="value=value.replace(/[^0-9]/g,'')" size="2"  style="width:170px"/>
       <br/>
		<small>(显示秒杀产品的数量)</small>
       </span> 
         <span style='float:left;display:inline-block;'>
        <label for="et_nums">开始时间: </label>
        
      <input type="text" class="Wdate" name="et_startdate" id="et_startdate" style="width:170px" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'#F{$dp.$D(\'et_enddate\')}'})"  value="" title="请输入开始秒杀时间"/>
    <br/>
		<small>(显示开始时间)</small>
        </span> 
        <span style='float:left;display:inline-block;'>
         <label for="et_nums">结束时间: </label>
        
      <input type="text" class="Wdate" name="et_enddate" id="et_enddate" style="width:170px" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'#F{$dp.$D(\'et_startdate\')}'})"  value="" title="请输入开始秒杀时间"/>
    <br/>
		<small>(显示开始时间)</small>
        </span> 
	</p>
    
    <p style="margin-bottom: 22px;">
		<label for="et_titlename">秒杀产品的二级标题: </label><br/>
		<input id="et_titlename" name="et_titlename"  style="width: 90%" value="<?php echo $titlename; ?>" /><br/>
        <br/>
		<small>(显示秒杀产品的二级标题)</small>
	</p>
    
    
	<?php
}

function et_post_active_title_meta($callback_args) {
	global $post;
	$thumbs = array();
	$custom    = get_post_custom($post->ID);
	$titlename     = isset($custom["titlename"][0]) ? $custom["titlename"][0] : '';
	
 ?>
     <p style="margin-bottom: 22px;">
		<label for="et_titlename">秒杀产品的二级标题: </label><br/>
		<input id="et_titlename" name="et_titlename"  style="width: 90%" value="<?php echo $titlename; ?>" /><br/>
        <br/>
		<small>(显示秒杀产品的二级标题)</small>
	</p>
	<?php
}

function save_details_active($post_id){
	global $post;
	
	if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) 
		return $post_id;
		
	if (isset($_POST["et_pos"]) && $_POST["et_pos"] <> '') update_post_meta($post->ID, "pos", $_POST["et_pos"]);
	if (isset($_POST["et_titlename"]) && $_POST["et_titlename"] <> '') update_post_meta($post->ID, "titlename", $_POST["et_titlename"]);
	
}
add_action('save_post', 'save_details_active');

function estore_upload_scripts_active() {
	wp_enqueue_script('media-upload');
	wp_enqueue_script('thickbox');
	wp_register_script('my-upload', get_bloginfo('template_directory').'/js/custom_uploader.js', array('jquery','media-upload','thickbox'));
	wp_register_script('my_area',get_bloginfo('template_directory').'/js/My97DatePicker/WdatePicker.js');
	wp_register_script('rw_post',get_bloginfo('template_directory').'/js/rw_post.js');
	wp_enqueue_script('my-upload');
	wp_enqueue_script('my_area');
	wp_enqueue_script('rw_post');
}
function estore_upload_styles_active() {
	wp_enqueue_style('thickbox');
}
add_action('admin_print_scripts', 'estore_upload_scripts_active');
add_action('admin_print_styles', 'estore_upload_styles_active');
?>
